const Address = require("../model/addrModel");
class AddressService {
  async createAddress(addr) {
    return await Address.create(addr);
  }
  async findAllAddress(user_id) {
    return await Address.findAll({
      attributes: ["id", "consignee", "phone", "address", "is_default"],
      where: { user_id },
    });
  }

  async updateAddress(id, addr) {
    return await Address.update(addr, { where: { id } });
  }
  async removeAddress(id) {
    return await Address.destroy({ where: { id } });
  }
  async setDefaultAddr(user_id, id) {
    await Address.update({ is_default: false }, { where: { user_id } });
    await Address.update({ is_default: true }, { where: {id} });
  }
}

module.exports = new AddressService();
